-- <nowiki>
local T = require('Module:Tool')
local V = require('Module:Value')

return {
    render = function(frame)
        local args = T.parseArgs(frame)

        local slotRaw = args.slot or args[1]
        local nameRaw = args.text or args[2]

        if slotRaw == nil then
            return T.error('[Template.G.render().slotRaw] is Nil: ' .. T.parseErrorValue(slotRaw))
        end

        local name = nameRaw or slotRaw
        local icon
        local iconFormat
        local link

        local glossary = V.glossary({slotRaw, '~'}) or {}

        if type(glossary) == 'table' then
            icon = glossary.icon
            iconFormat = glossary.iconFormat
            link = glossary.link
            name = nameRaw or glossary.name
        end

        local span = mw.html.create('span')

        local hasContent = false

        if icon ~= nil and icon ~= false and mw.text.trim(tostring(icon)) ~= '' then
            hasContent = true

            span:wikitext(string.format('[[File:%s.%s|x20px|link=%s|alt=%s]]', icon, iconFormat, link, name))
        end

        if type(name) == 'string' and mw.text.trim(tostring(name)) ~= '' then
            hasContent = true

            if type(link) == 'string' and mw.text.trim(tostring(link)) ~= '' then
                span:wikitext(string.format('[[%s|%s]]', link, name))
            else
                span:wikitext(name)
            end
        end

        if hasContent then
            span:addClass('glossary'):addClass('LOLContent'):addClass('TemplateG')
        end

        return tostring(span)
    end
}
-- </nowiki>
-- [[Category:Module]][[Category:Module/Template]]
